package com.baturu.vin.gm.dal.dao;

import com.baturu.vin.gm.dto.GMPartsDetailDTO;
import com.baturu.vin.gm.dto.PartsImageInfoDTO;
import com.baturu.vin.gm.dto.PartsPositionDTO;
import com.baturu.vin.gm.dto.PartsPositionQueryParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;
import java.util.Set;


public interface PartsPositionDAO {

    @Select("<script>" +
            "SELECT  subject1 subject,position_X positionX,position_Y positionY,part_code positionNo,catalog_Code catalogCode " +
            "FROM gm_epc_cd_partposition " +
            "WHERE (subject1,part_code,catalog_Code) IN " +
            "<foreach item='item' index='index' collection='partsPositionQueryParam' open='(' separator=',' close=')'>" +
            "(#{item.subject},#{item.partNo},#{item.catalogCode})" +
            "</foreach>" +
            "</script>")
    List<PartsPositionDTO> findPartsPositions(@Param("partsPositionQueryParam") List<PartsPositionQueryParam> partsPositionQueryParam);

    @Select("<script>" +
            "SELECT parts_code partsCode,body,Catalog_Code CatalogCode,series,First_Year firstYear,Last_Year lastYear,kit,`subject`,Option_P optionP,Option_N optionN,callout pictureNO,Quantity,Part_Name_CN  partNameCN,group_Code groupCode  " +
            "FROM gm_epc_cd_partdetail " +
            "WHERE catalog_Code = #{catalogCode} and subject IN " +
            "<foreach item='item' index='index' collection='subjects' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<GMPartsDetailDTO> queryPartsDetail(@Param("catalogCode") String catalogCode, @Param("subjects") List<String> partsCodes);

    @Select("<script>" +
            "SELECT DISTINCT sortName,artNumber " +
            "FROM gm_epc_image_info INNER JOIN gm_part_detail ON gm_part_detail.`subject` = gm_epc_image_info.artNumber " +
            "WHERE catalogCode = #{catalogCode} AND sortName IN " +
            "<foreach item='item' index='index' collection='sortNames' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<PartsImageInfoDTO> queryPartsImageInfo(@Param("sortNames") List<String> sortNames, @Param("catalogCode") String catalogCode);

    @Select("SELECT t.Description_CN des, t.subject artNumber, t.catalog_Code catalogCode " +
            "FROM gm_epc_cd_subjectdesc t  " +
            "WHERE t.catalog_code = #{catalogCode} ")
    Set<PartsImageInfoDTO> queryPartsImageV2Info(@Param("catalogCode") String catalogCode);

    @Select({"<script>" ,
            "SELECT  artNumber,artNameCN des" ,
            "FROM gm_epc_image_info  " ,
            "WHERE artNumber IN " ,
            "<foreach item='item' index='index' collection='subject' open='(' separator=',' close=')'>" ,
            "#{item}" ,
            "</foreach>" ,
            "</script>"})
    Set<PartsImageInfoDTO> queryPicDesBySubject(@Param("subject") Set<String> subject);

    @Select({"<script>" +
            "SELECT  subject1 subject,position_X positionX,position_Y positionY,part_code positionNo,catalog_Code catalogCode " +
            "FROM gm_epc_cd_partposition " +
            "WHERE part_code IN " +
            "<foreach item='item' index='index' collection='positions' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" ,
            "AND catalog_Code = #{catalog}",
            "AND subject1 = #{subject}",
            "</script>"})
    List<PartsPositionDTO> queryImagePosition(@Param("catalog") String catalog, @Param("subject") String subject, @Param("positions") Collection<String> positions);

    @Select({"<script>" +
            "SELECT  subject1 subject,position_X positionX,position_Y positionY,part_code positionNo,catalog_Code catalogCode " +
            "FROM gm_epc_cd_partposition " +
            "WHERE part_code IN " +
            "<foreach item='item' index='index' collection='positions' open='(' separator=',' close=')'>" +
            "#{item}" ,
            "</foreach>" ,
            "AND catalog_Code = #{catalog}",
            "AND subject1 in " ,
            "<foreach item='item' index='index' collection='subjects' open='(' separator=',' close=')'>" ,
            "#{item}",
            "</foreach>" ,
            "</script>"})
    List<PartsPositionDTO> queryImagePositionByParts(@Param("catalog") String catalog, @Param("subjects") Collection<String> subject, @Param("positions") Collection<String> positions);
}
